//
//  SHStatusRetweetView.swift
//  SHWeibo3
//
//  Created by teacher on 16/7/23.
//  Copyright © 2016年 teacher. All rights reserved.
//  

import UIKit
import SnapKit
class SHStatusRetweetView: UIView {
    // 记录转发微博的底部约束
    var retweetViewBottomConstraint: Constraint?
    // 供外界赋值
    var statusViewModel: AYuStatusViewModel?{
        didSet{
            contentLabel.text = statusViewModel?.status?.retweeted_status?.text
            
            // 卸载约束
            retweetViewBottomConstraint?.uninstall()
            // 代表有配图
            if statusViewModel?.status?.retweeted_status?.pic_urls?.count > 0 {
                // 01 赋值
                pictureView.pictureInfo = statusViewModel?.status?.retweeted_status?.pic_urls
                // 02 更改约束
                self.snp_makeConstraints { (make) -> Void in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(statusCellMargin).constraint
                }
                // 03 显示配图
                pictureView.hidden = false
            }else {
                // 代表没有配图
                
                // 01 更改约束
                self.snp_makeConstraints { (make) -> Void in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(statusCellMargin).constraint
                }
                // 02 显示配图
                pictureView.hidden = true
            }

        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = RGB(237, green: 237, blue: 237)
        // 01 添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        // 02 添加约束
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.leading.equalTo(10)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(statusCellMargin)
            make.leading.equalTo((SCREENW - (cellWH*3 + cellMargin*2))/2)
        }
        // 约束当前的view
        self.snp_makeConstraints { (make) -> Void in
            self.retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }

    }
    
    // MARK: - 懒加载控件
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWidth: SCREENW - 20)
    // 配图
    private lazy var pictureView: AYuStatusPictureView = AYuStatusPictureView()
}
